package org.erepublik.company;

import org.erepublik.company.searchCriteria.ERawRegion;
import org.json.JSONException;
import org.json.JSONObject;

public class Region implements JSONAble {

    private int id;
    private String name;
    private ERawRegion oil;
    private ERawRegion titanium;
    private ERawRegion grain;
    private ERawRegion stone;
    private ERawRegion iron;
    private ECountry country;   
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public ERawRegion getOil() {
        return oil;
    }
    public void setOil(ERawRegion oil) {
        this.oil = oil;
    }
    public ERawRegion getTitanium() {
        return titanium;
    }
    public void setTitanium(ERawRegion titanium) {
        this.titanium = titanium;
    }
    public ERawRegion getGrain() {
        return grain;
    }
    public void setGrain(ERawRegion grain) {
        this.grain = grain;
    }
    public ERawRegion getStone() {
        return stone;
    }
    public void setStone(ERawRegion stone) {
        this.stone = stone;
    }
    public ERawRegion getIron() {
        return iron;
    }
    public void setIron(ERawRegion iron) {
        this.iron = iron;
    }
    public ECountry getCountry() {
        return country;
    }
    public void setCountry(ECountry country) {
        this.country = country;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
    
    @Override
    public JSONObject toJSONObject() throws JSONException {

        JSONObject object = new JSONObject();
        object.put("id", getId());
        object.put("country", getCountry().toString());
        object.put("name", getName());
        object.put("oil", getOil().toString());
        object.put("grain", getGrain().toString());
        object.put("iron", getIron().toString());
        object.put("titanium", getTitanium().toString());
        object.put("stone", getStone().toString());
        
        return object;
    }

    public static Region getFromJSON(JSONObject object) throws JSONException {
        Region region = new Region();
        region.setCountry( ECountry.valueOf( object.getString("country") ) );
        region.setId( object.getInt("id") );
        region.setName( object.getString("name") );
        region.setGrain( ERawRegion.valueOf( object.getString("grain") ) );
        region.setOil( ERawRegion.valueOf( object.getString("oil") ) );
        region.setIron( ERawRegion.valueOf( object.getString("iron") ) );
        region.setTitanium( ERawRegion.valueOf( object.getString("titanium") ) );
        region.setStone( ERawRegion.valueOf( object.getString("stone") ) );
        
        return region;
    }
    
    
}
